# import os
# from webbrowser import Chrome
#
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service as ChromeService, Service
# from selenium.webdriver.common.by import By
# from webdriver_manager.chrome import ChromeDriverManager
# #驱动程序管理的⾃动化
# #创建驱动对象
# #1.打开浏览器
# driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
#
# # # 设置镜像源和禁用SSL验证
# # os.environ['WDM_HTTPCLIENT'] = 'httpx'
# # os.environ['WDM_LOCAL'] = '1'
# # os.environ['WDM_SSL_VERIFY'] = '0'  # 临时关闭SSL验证（非安全环境）
# #
# # # 指定镜像URL（如淘宝镜像）
# # os.environ['WDM_CHROMEURL'] = 'https://npm.taobao.org/mirrors/chromedriver/'
# #
# # # 安装并启动ChromeDriver
# # driver = Chrome(service=Service(ChromeDriverManager().install()))
#
# #2.输⼊百度⽹址:https://www.baidu.com
# driver.get("https://www.baidu.com")
# #3、找到输⼊框并输⼊“迪丽热巴”
# driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("迪丽热巴")
# #4、找到“百度⼀下”按钮并点击
# driver.find_element(By.CSS_SELECTOR,"#su").click()
# #5、关闭浏览器
# driver.quit()
import datetime
import multiprocessing
import os
import sys
import threading
import time
from calendar import weekday
from enum import Enum, unique
from multiprocessing import Process
from typing import Iterable


# class WeekDay(Enum):
#     Mon = 0
#     Tue = 1
#     Wed = 2
#     Thu = 3
#     Fri = 4
#
#
# for day in WeekDay:
#     # 枚举成员
#     print(day)
#     # 枚举成员名称
#     print(day.name)
#     # 枚举成员值
#     print(day.value)
#
# print(list(WeekDay))
#
# print(WeekDay.Mon is WeekDay.Thu)
# print(WeekDay.Mon == WeekDay.Mon)
# print(WeekDay.Mon.name == WeekDay.Mon.name)
# print(WeekDay.Mon.value == WeekDay.Mon.value)

# class Cat:
# 	# 属性
#     color = 'black'
#     __cid = '1'#__开头表示私有
#     # 构造方法
#     def __init__(self, name):
#         self.name = name
#     # 自定义方法
#     def eat(self, food):
#         self.food = food
#         print(self.name, '正在吃'+food)
#
#     def __run(self, speed):#私有方法
#         print('__cid是' + self.__cid + '的猫', '以' + speed + '迈的速度奔跑')
#
#     def run(self, speed):
#         self.__run(speed)
#
# # print('color-->', Cat.color)
# # c1=Cat("haha")
# # c1.eat("鱼")
# # c1.run('50')
#
# # 波斯猫类
# class PersianCat(Cat):
#     def __init__(self, name):
#         self.name = name
#     def eat(self, food):
#         print(self.name, '正在吃'+food)
# #加菲猫类
# class GarfieldCat(Cat):
#     def __init__(self, name):
#         self.name = name
#     def run(self, speed):
#         print(self.name, '正在以'+speed+'的速度奔跑')
# # 单继承
# class SingleCat(PersianCat):
#     def eat(self, food ):#重写父类方法
#         print(self.name, '正在吃'+food, '十分钟后', self.name+'吃饱了')
# # 多继承
# class MultiCat(PersianCat, GarfieldCat):
#     pass
#
# # #调用
# # sc = SingleCat('波斯猫1号')
# # sc.eat('鱼')
# #
# # mc = MultiCat('波斯加菲猫1号')
# # mc.eat('鱼')
# # mc.run('50迈')
#
# # isinstance() 方法来判断一个对象是否为可迭代对象
# print(isinstance('abc', Iterable))
# print(isinstance({1, 2, 3}, Iterable))
# print(isinstance(1024, Iterable))
#
# # 生成器
# def reverse(data):
#     for i in range(len(data)-1, -1, -1):
#         yield data[i]
# for char in reverse('Hello'):
#     print(char)
#
# # 列表
# lis = [x*x for x in range(5)]
# print(lis)
#
# # 生成器
# gen = (x*x for x in range(5))
# for g in gen:
#     print(g)
#
# # 装饰函数
# def funA(fun):#接收的是要装饰的函数funC
#     def funB(*args, **kw):#接收的是要装饰的函数funC的参数
#         print('函数 ' + fun.__name__ + ' 开始执行')
#         fun(*args, **kw)
#         print('函数 ' + fun.__name__ + ' 执行完成')
#     return funB
#
# @funA
# # 业务函数
# def funC(name):
#   print('Hello', name)
#
# funC('Jhon')

# fun=funA(funC)
# fun("Jhon")


#带参数的装饰函数
# def funA(flag):
#     def funB(fun):#接收的是要装饰的函数funD
#         def funC(*args):#接收的是要装饰的函数funD的参数
#             print(*args)
#             if flag == True:
#                 print('==========')
#             elif flag == False:
#                 print('----------')
#             fun(*args)
#         return funC
#     return funB
#
# @funA(False)
# # 业务函数
# def funD(name):
#   print('Hello', name)
#
# funD('Jhon')

## 装饰类
# class Test(object):
#     def __init__(self, func):
#         print(f'函数名是:{func.__name__}')
#         self.__func = func
#
#     def __call__(self, *args, **kwargs):
#         self.__func(*args)
#
# # 装饰器业务函数
# @Test
# def hello(a=10,b=20):
#     print(f'Hello ... {a+b}')
#
# hello()
# hello(100,200)
#
# # 函数作为参数直接传递
# def haha(a=30,b=40):
#     print(f'haha ... {a+b}')
#
# test=Test(haha)
# test()
# test(3,4)

# class MyIterator:
#     def __init__(self):
#         self.s = "asdfghj"
#         self.i = 0
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         if self.i < len(self.s):
#             n = self.s[self.i]
#             self.i += 1
#             return n
#         else:
#             raise StopIteration
#
# # 使用iter()函数生成一个可迭代对象
# mi = iter(MyIterator())
# for i in mi:
#     print(i,end=' ')
#
# print()
#
# #通过__iter__()方法生成可迭代对象
# mi = MyIterator()
# for i in mi:
#     print(i,end=' ')


# # 列表
# lis = [x*x for x in range(5)]
# print(lis)
#
# # 生成器
# gen = (x*x for x in range(5))
# for g in gen:
#     print(g)

# # 枚举
# @unique #@unique装饰器保证枚举值唯一
# class WeekDay(Enum):
#     Mon = 0
#     # Tue = 0
#     Tue = 1
#     Wed = 2
#     Thu = 3
#     Fri = 4
#
# for day in WeekDay:
#     # 枚举成员
#     print(day,end=' ')
#     # 枚举成员名称
#     print(day.name,end=' ')
#     # 枚举成员值
#     print(day.value,end=' ')
#     print()
#
# print(list(WeekDay))


# # 除0错误
# def getNum(n):
#     try:
#         try:
#             return 10 / n
#         except IOError:
#             print('Error: IOError argument.')
#         except SyntaxError:
#             print('Error: SyntaxError argument.')
#     except ZeroDivisionError:
#         print("Error: ZeroDivisionError argument.")


#def getNum(n):
#     try:
#         print('try --> ',10 / n)
#     except ZeroDivisionError:
#         print('except --> Error: ZeroDivisionError argument.')
#     else:#放在execpt之后，只有没有异常时执行
#         print('else -->')
#     finally:#有没有异常都执行
#         print('finally -->')
#
# getNum(0)
#
# getNum(1)


# # 查看当前路径
# print(os.getcwd())
#
# # 返回指定目录下包含的文件和目录名列表
# print(os.listdir('D:/Python/PyCharm'))
#
# # 返回路径 path 的绝对路径
# print(os.path.abspath('.'))
#
# # 调研shell
# # print(os.system("ping www.baidu.com"))
#
# path="D:/Python/PyCharm/Project/test3/test.txt"
#
# # 将路径 path 拆分为目录和文件两部分
# print(os.path.split(path))
#
# # 将一个或多个 path（文件或目录） 进行拼接
# print(os.path.join("D:/Python/PyCharm","test.txt"))
#
# # 返回 path（文件或目录） 在系统中的创建时间（时间戳）
# print(os.path.getctime(path))
#
# # 返回 path（文件或目录） 最近的修改时间（时间戳）
# print(os.path.getmtime(path))
#
# # 返回 path（文件或目录） 最近的访问时间（时间戳）
# print(os.path.getatime(path))
#
# # 判断 path（文件或目录）是否存在，存在返回 True，否则返回 False
# print(os.path.exists(path))
# print(os.path.exists("D:/Python/PyCharm/test.txt"))
#
# # 返回 path 的大小（包括换行符），以字节为单位，若 path 是目录则返回 0
# print(os.path.getsize(path))
# print(os.path.getsize("D:/Python/PyCharm"))
# # print(os.path.getsize("D:/Python/PyCharm/test.txt"))#不存在的文件会报错

#from pg1.a import a
# from pg1.b import b
#
# from pg2.c import c
# from pg2.d import d
#
# a()
# b()
# c()
# d()


# # 空函数
# def my_empty():
#     pass
#
# # 无返回值
# def my_print(name):
#     print('Hello', name)
#
# # 有返回值
# def my_sum(x, y):
#     s = x + y
#     print('s-->', s)
#     return s
#
# # 不定长参数
# def my_variable(*params):
#     for p in params:
#         print(p)
# # 匿名函数
# my_sub = lambda x, y: x - y
#
# my_empty()
# my_print("nihao")
# my_sum(1,2)
# my_variable(1,2,3,4,5)
# print(my_sub(3,4))

# t = time.localtime()
# print(t)
# print("------------------time类-----------------------")
#
# print(time.time())
# print(time.gmtime())
# print(time.localtime())
# print(time.asctime(time.localtime()))
# print(time.tzname)
# # strftime 使用
# print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
#
# print("------------------time实例-----------------------")
#
# t = datetime.time(10, 10, 10)
# print(t.isoformat())
# print(t.replace(hour=9, minute=9))
# print(t.strftime('%I:%M:%S %p'))
# print(t.hour)
# print(t.minute)
# print(t.second)
# print(t.microsecond)
# print(t.tzinfo)
#
# print("------------------date类------------------------")
#
# print(datetime.date.today())
# print(datetime.date.fromtimestamp(time.time()))
# print(datetime.date.min)
# print(datetime.date.max)
#
# print("-----------------date实例------------------------")
# # 实例使用
# td = datetime.date(1,1,1)
# print(td.replace(year=1945, month=8, day=15))
# print(td.timetuple())
# print(td.weekday())
# print(td.isoweekday())
# print(td.isocalendar())
# print(td.isoformat())
# print(td.strftime('%Y %m %d %H:%M:%S %f'))
# print(td.year)
# print(td.month)
# print(td.day)
#
# print("------------------datetime类-----------------------")
#
# print(datetime.datetime.today())
# print(datetime.datetime.now())
# print(datetime.datetime.utcnow())
# print(datetime.datetime.fromtimestamp(time.time()))
# print(datetime.datetime.utcfromtimestamp(time.time()))
# print(datetime.datetime.combine(datetime.date(2019, 12, 1), datetime.time(10, 10, 10)))
# print(datetime.datetime.min)
# print(datetime.datetime.max)
#
# print("------------------datetime实例-----------------------")
#
# td = datetime.datetime(2,2,2)
# print(td.date())
# print(td.time())
# print(td.replace(day=11, second=10))
# print(td.weekday())
# print(td.isoweekday())
# print(td.isocalendar())
# print(td.isoformat())
# print(td.strftime('%Y-%m-%d %H:%M:%S .%f'))
# print(td.year)
# print(td.month)
# print(td.month)
# print(td.hour)
# print(td.minute)
# print(td.second)
# print(td.microsecond)
# print(td.tzinfo)

# print(dir(sys))
#
# print(sys.version)
# print(sys.winver)
# print(sys.platform)
# print(sys.path)
# print(sys.maxsize)
# print(sys.maxunicode)
# print(sys.copyright)
# print(sys.modules)
# print(sys.byteorder)
# print(sys.executable)

# count=0
#
# def target():
#     # print('当前线程为:', threading.current_thread().name)
#     global count
#     i=0
#     while i<1000000:
#         count += 1
#         i+=1
#         # print(f"count:{count}")
#     # print(f"count:{count}")
#
#
#
# if __name__ == '__main__':
#     t1 = threading.Thread(name='t1', target=target)
#     t2 = threading.Thread(name='t2', target=target)
#     time.sleep(2)
#     t1.start()
#     t2.start()
#
#     t1.join()
#     t2.join()
#     print(count)
#     print('主线程结束')

# class MyThread(threading.Thread):
#     def __init__(self, sleep, name):
#         super().__init__()
#         self.sleep = sleep
#         self.name = name
#     def run(self):
#         time.sleep(self.sleep)
#         print('name：' + self.name)
#
# if __name__ == '__main__':
#     t1 = MyThread(1, 't1')
#     t2 = MyThread(1, 't2')
#     t1.start()
#     t2.start()

# a = 5
# def oper(b):
#     global a
#     a = a - b
#     a = a + b
#
# def target(b):
#     for i in range(100000):
#         oper(b)
#
# if __name__ == '__main__':
#     m = 5
#     while m > 0:
#         t1 = threading.Thread(target=target, args=(1,))
#         t2 = threading.Thread(target=target, args=(2,))
#         t1.start()
#         t2.start()
#         t1.join()
#         t2.join()
#         print(a)
#         m = m - 1

# # 创建锁
# lock = threading.Lock()
#
# a = 5
# def oper(b):
#     # 获取锁
#     lock.acquire()
#     global a
#     a = a - b
#     a = a + b
#     # 释放锁
#     lock.release()
#
# def target(b):
#     for i in range(100000):
#         oper(b)
#
# if __name__ == '__main__':
#     m = 5
#     while m > 0:
#         t1 = threading.Thread(target=target, args=(1,))
#         t2 = threading.Thread(target=target, args=(2,))
#         t1.start()
#         t2.start()
#         t1.join()
#         t2.join()
#         print(a)
#         m = m - 1


# # 创建条件对象
# c = threading.Condition()
# privilege = 0
#
# def getPri():
#     global privilege
#     c.acquire()
#     c.wait()
#     print(privilege)
#     c.release()
#
# def updPri():
#     time.sleep(5)
#     print("唤醒线程休眠结束……")
#     c.acquire()
#     global privilege
#     privilege = 1
#     c.notify()
#     c.release()
#
# if __name__ == '__main__':
#     t1 = threading.Thread(target=getPri)
#     t2 = threading.Thread(target=updPri)
#     t1.start()
#     t2.start()

# # 创建信号量对象
# s = threading.Semaphore(10)
#
# a = 5
# def oper(b):
#     # 获取信号量
#     s.acquire()
#     global a
#     a = a - b
#     a = a + b
#     # 释放信号量
#     s.release()
#
# def target(b):
#     for i in range(100000):
#         oper(b)
#
# if __name__ == '__main__':
#     m = 5
#     while m > 0:
#         t1 = threading.Thread(target=target, args=(1,))
#         t2 = threading.Thread(target=target, args=(2,))
#         t1.start()
#         t2.start()
#         t1.join()
#         t2.join()
#         print(a)
#         m = m - 1

# def target():
#     time.sleep(2)
#     print ('子进程ID：', os.getpid())
#
# # 多进程
# if __name__=='__main__':
#     print ('主进程ID：', os.getpid())
#     ps = []
#     for i in range(10):
#         p = Process(target=target)
#         p.start()
#         ps.append(p)
#     for p in ps:
#         p.join()
#

def target(p):
    print('t')
    time.sleep(2)
    print(p)

# 进程池
if __name__ == "__main__":
    pool = multiprocessing.Pool(processes = 5)
    for i in range(3):
        p = 'p%d'%(i)
        # 阻塞式
        pool.apply(target, (p, ))
        # 非阻塞式
        # pool.apply_async(target, (p, ))
    pool.close()
    pool.join()